package br.edu.sistemaacademico.helper;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Conexao {

	private static Connection conexao;
	private static String url = 
		"jdbc:derby://localhost:1527/SISTEMACADEMICO";
	private Conexao() {
		super();
		
	}
	public static Connection getConexao(){
		if (conexao == null){
			try{
				Class.forName("org.apache.derby.jdbc.ClientDriver");
				conexao =  (Connection) DriverManager.getConnection(url);
			}catch(ClassNotFoundException e){
				e.printStackTrace();
			}catch(SQLException e){
				e.printStackTrace();
			}
			return conexao;
		}else{
			return conexao;
		}
	}
	public static void fecharConexao(){
		if(conexao!=null)
			try {
				conexao.close();
			} catch (SQLException e) {e.printStackTrace();}
			conexao = null;
	}
}
